package com.sjf.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sjf.common.Result;
import com.sjf.reggie.entity.Orders;
import com.sjf.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author <huangtang>
 * @since 2022/4/27 17:02
 **/
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public Result<String> submit( @RequestBody Orders orders ) {
        log.info ("提交订单:{}", orders);
        ordersService.submit (orders);
        return Result.success ("下单成功");
    }

    @GetMapping("/userPage")
    public Result<Page> getList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                @RequestParam(value = "pageSize") Integer pageSize) {
        return Result.success(ordersService.getList(page,pageSize));
    }


}
